package twentytwenty;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2020-12-04 13:44
 * @Modified By:
 */
public class Generate_118 {
    public static void main(String [] args){
        System.out.println(generate(5));
    }

    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result = new ArrayList<>();
        for (int i = 1; i <= numRows; i++) {
            List<Integer> row = new ArrayList<>();
            int next = 0;
            for (int j = 1; j <= i; j++) {
                if (j == 1 || j == i){
                    row.add(1);
                }else {
                    row.add(result.get(i - 2).get(next) + result.get(i - 2).get(next + 1));
                    next ++;
                }
            }
            result.add(row);
        }
        return result;
    }
}
